package com.misty.observer_pattern.observer1;

import java.util.ArrayList;
import java.util.List;

public class HanFeiZi implements IHanfeizi, Observable {
    private List<Observer> observers = new ArrayList<>();

    @Override
    public void haveBreakfast() {
        System.out.println("韩非子吃饭");
        this.notifyObservers("报告：韩非子吃饭了");
    }

    @Override
    public void haveFun() {
        System.out.println("韩非子娱乐");
        this.notifyObservers("报告：韩非子娱乐了");
    }

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String context) {
        for (Observer observer : observers) {
            observer.update(context);
        }
    }
}
